/**
 * 
 */
package sqs.dataaccess.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import sqs.dataaccess.UserDao;
import sqs.model.User;

/**
 * @author kjleng
 *
 */
public class HibernateUserDao extends HibernateDaoSupport implements UserDao {

	public User getUserByUsername(String username) throws DataAccessException {
		Query query = getSession().createQuery("from User u where u.username=?");
		query.setParameter(0, username);
		return (User)query.uniqueResult();
	}
	
	public List<User> getAllUsers() throws DataAccessException{
		Query query = getSession().createQuery("from User u ");
		return query.list();
	}

	public void createUser(User user) throws DataAccessException {
		getHibernateTemplate().save(user);
	}

	public void updateUser(User user) throws DataAccessException {
		getHibernateTemplate().update(user);
	}

}
